<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="frame/header.jsp"></jsp:include>

<title>新增商家信息</title>
</head>

<body>
	<div class="container-fluid">
		<div class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">商家管理</a> <span class="divider">/</span></li>
					<li><a href="#">新增商家</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-edit"></i> 编辑商家信息
					</h2>
					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<form id="myform" class="form-horizontal" method="post" action="<c:url value="/seller/seller" />">
						<fieldset>
							<input type="hidden" name="sellerId" value="${seller.sellerId }">
							
							<div class="control-group">
								<label class="control-label" for="sellerName">商家名称</label>
								<div class="controls">
									<input class="input-xlarge" id="sellerName" name="sellerName" type="text"
										value="${seller.sellerName }" maxlength="50" check-type="required" required-message="请输入商家名称">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="address">商家地址</label>
								<div class="controls">
									<input class="input-xlarge" id="address" name="address" type="text"
										value="${seller.address }" maxlength="50" check-type="required" required-message="请输入商家地址">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="tel">联系电话</label>
								<div class="controls">
									<input class="input-xlarge" id="tel" name="tel" type="text"
										value="${seller.tel }" maxlength="30" >
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="phone">手机号</label>
								<div class="controls">
									<input class="input-xlarge" id="phone" name="phone" type="text"
										value="${seller.phone }" maxlength="30" >
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="foodType">所属菜系</label>
								<div class="controls">
									<select id="foodType" name="foodType" class="input-xlarge" multiple data-rel="chosen">
										<c:forEach var="foodType" items="${foodTypes }">
											<option value="${foodType.typeId }">
												${foodType.typeName}
											</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="fileInput">上传照片</label>
								<div class="controls">
									<input class="input-file uniform_on" name="file"
										id="userHeader" type="file"> <input type="button"
										value="upload" onclick="return ajaxFileUpload();">
								</div>
								<img id="loading" class="hide" src="<c:url value="/resources/img/ajax-loader-6.gif"/>">
								<input type="hidden" name="pic" id="pic" value="${seller.pic }">
							</div>
							<div class="control-group">
								
								<div class="controls">
									<img id="picture" src='${seller.pic }' class="input-xxlarge">
								</div>
								
							</div>
							<div class="control-group">
								<label class="control-label" for="description_mc">商家描述</label>
								<div class="controls">
									<textarea id="description_mc" name="description_mc" rows="12"
										class="xheditor-simple input-xxlarge">${seller.description_mc }</textarea>
								</div>
							</div>
							
							<div class="form-actions">
								<button id="saveBtn" type="button" class="btn btn-primary">保存</button>
								<button id="cancelBtn" type="button" class="btn">返回</button>
							</div>
						</fieldset>
					</form>

				</div>
			</div>
			<!--/span-->

		</div>
	</div>
	<!--/row-->
</body>

<jsp:include page="frame/scripts.jsp"></jsp:include>
<script type="text/javascript">
$(document).ready(function(){
	
	
	
	$('#cancelBtn').click(function(){
		window.location.href = '<c:url value="/seller/seller" />';	
	})
	
	$("#myform").validation();
	
	var foodType = '${seller.foodType}';
	if('' != foodType){
		var ids = foodType.split(',');
		for(var i in ids){
			$('#foodType').find('option[value="'+ids[i]+'"]').prop('selected',true);
		}
		
	}
	$('[data-rel="chosen"],[rel="chosen"]').chosen();
	
	//保存
	$('#saveBtn').click(function(){
		$("#myform").submit();
	})
})

//上传图片
function ajaxFileUpload(){
	
	$("#loading").ajaxStart(function(){
		//开始上传文件时显示一个图片
		$(this).show();
	}).ajaxComplete(function(){
		//文件上传完成将图片隐藏起来
		$(this).hide();
	});
	
	$.ajaxFileUpload({
		url:'<c:url value="/fileupload"/>',//用于文件上传的服务器端请求地址
		secureuri:false,//一般设置为false
		fileElementId:'userHeader',//文件上传空间的id属性  <input type="file" id="file" name="file" />
		dataType: 'JSON',//返回值类型 一般设置为json(大写)
		success: function (data, status){
			var image = DOMAIN + '/resources/fileupload/'+$(data).html();
			$("#picture").attr('src',image).show();
			$("input[name='pic']").val(image);
		},
		error: function (data, status, e){
			alert(e);
		}	
	})
	
	return false;
}
</script>